package cate.game.role.pvp.pointrace;

import cate.common.table.d.GDFight;
import cate.common.table.d.GDHoardTask;
import cate.common.table.d.GDOperation;
import cate.common.table.d.GDVideoHall;
import cate.game.play.proce.play.PlayPO;
import cate.game.play.vo.PlayReportVO;
import cate.game.res.MixRes;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;
import cate.game.role.pvp.PvpRecord;
import cate.game.role.pvp.pointrace.msg.PointRaceChallengeResultResp;
import cate.game.videohall.po.ReplayProfile;
import cate.game.videohall.po.VideoPO;


public class PointRaceFTC extends AbstractFarmFTC<PointRace> {

    public PointRaceFTC() {
    }

    @Override
    protected PointRace po(Role role) {
        return role.getPvp().pointRace;
    }

    @Override
    public void handleResult(Role role, PlayPO play) {
        super.handleResult(role, play);
        role.getGame().facilities.getMongo().play.save(play);
        role.getGame().videoHall.addVideo(GDVideoHall.Group.POINT_RACE, play);
        PointRace po = po(role);
        PvpRecord record = po.lastInitiativeRecord;
        if (record != null) {
            PointRaceChallengeResultResp resultResp = new PointRaceChallengeResultResp();
            resultResp.winner = play.winner;
            resultResp.snapshotA = play.a.snapshot;
            resultResp.snapshotB = play.b.snapshot;
            resultResp.pointsA = record.valueA;
            resultResp.pointsB = record.valueB;
            resultResp.pointsChangeA = record.valueChangeA;
            resultResp.pointsChangeB = record.valueChangeB;
            MixRes reward;
            if (play.winner == GDFight.Team.A) {
                reward = new MixRes(role.getGame().table.pointRace.challengeReward.getReward(true));
                role.getHistory().action.pointRaceWin();
                role.getRes().hoard.addition.addTask(GDHoardTask.POINT_RACE);
            } else {
                reward = new MixRes(role.getGame().table.pointRace.challengeReward.getReward(false));
                role.getHistory().action.pointRaceLose();
            }
            role.log.setOperation(GDOperation.POINT_RACE_CHALLENGE);
            reward.add(role, true, GDOperation.POINT_RACE_CHALLENGE);
            role.log.clearOperation();
            resultResp.reward = reward;
            if (skip) {
                resultResp.report = new PlayReportVO(play);
            }
            role.sendNow(resultResp);
        }
        po.lastInitiativeRecord = null;
        po.noticeUpdate();
    }
}
